#include<unistd.h>
#include<iostream>
using namespace std;

int main()
{
    int pipefd[2];
    int ret = pipe(pipefd);
    if(ret < 0)
    {
        cout << "Create pipe unsuccess" << endl;
        exit(-1);
    }

    int pid = fork();
    if(pid == 0) //子进程
    {
        close(pipefd[1]);
        char buff[1024];
        while(true)
        {

            int n = read(pipefd[0],buff,sizeof(buff)-1);
            if(n < 0)
            {
                break;
            }
            buff[n] = 0;
            cout << buff << endl;
            sleep(1);
        }
        exit(0);
    }

    close(pipefd[0]);
    char buff[] = "i am fathe";
    while(true)
    {
        int n = write(pipefd[1],buff,sizeof(buff)-1);
        sleep(1);
    }


    return 0;
}

